home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JDDEFLTS.C < prev    next >
C/C++ Source or Header  |  1991-12-12  |  4KB  |  118 lines

  1. /*
  2.  * jddeflts.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains optional default-setting code for the JPEG decompressor.
  9.  * User interfaces do not have to use this file, but those that don't use it
  10.  * must know more about the innards of the JPEG code.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15.  
  16. /*
  17.  * Reload the input buffer after it's been emptied, and return the next byte.
  18.  * See the JGETC macro for calling conditions.
  19.  *
  20.  * This routine is used only if the system-dependent user interface passes
  21.  * standard_buffering = TRUE to j_d_defaults.  Otherwise, the UI must supply
  22.  * a corresponding routine.  Note that in any case, this routine is likely
  23.  * to be used only for JFIF or similar serial-access JPEG file formats.
  24.  * The input file control module for a random-access format such as TIFF/JPEG
  25.  * would need to override the read_jpeg_data method with its own routine.
  26.  *
  27.  * This routine would need to be replaced if reading JPEG data from something
  28.  * other than a stdio stream.
  29.  */
  30.  
  31. METHODDEF int
  32. read_jpeg_data (decompress_info_ptr cinfo)
  33. {
  34.   cinfo->next_input_byte = cinfo->input_buffer + MIN_UNGET;
  35.  
  36.   cinfo->bytes_in_buffer = (int) FREAD(cinfo->input_file,
  37.                        cinfo->next_input_byte,
  38.                        JPEG_BUF_SIZE);
  39.   
  40.   if (cinfo->bytes_in_buffer <= 0)
  41.     ERREXIT(cinfo->emethods, "Unexpected EOF in JPEG file");
  42.  
  43.   return JGETC(cinfo);
  44. }
  45.  
  46.  
  47.  
  48. /* Default parameter setup for decompression.
  49.  *
  50.  * User interfaces that don't choose to use this routine must do their
  51.  * own setup of all these parameters.  Alternately, you can call this
  52.  * to establish defaults and then alter parameters selectively.  This
  53.  * is the recommended approach since, if we add any new parameters,
  54.  * your code will still work (they'll be set to reasonable defaults).
  55.  *
  56.  * standard_buffering should be TRUE if the JPEG data is to come from
  57.  * a stdio stream and the user interface isn't interested in changing
  58.  * the normal input-buffering logic.  If FALSE is passed, the user
  59.  * interface must provide its own read_jpeg_data method and must
  60.  * set up its own input buffer.  (Alternately, you can pass TRUE to
  61.  * let the buffer be allocated here, then override read_jpeg_data with
  62.  * your own routine.)
  63.  */
  64.  
  65. GLOBAL void
  66. j_d_defaults (decompress_info_ptr cinfo, boolean standard_buffering)
  67. /* NB: the external methods must already be set up. */
  68. {
  69.   /* Default to RGB output */
  70.   /* UI can override by changing out_color_space */
  71.   cinfo->out_color_space = CS_RGB;
  72.   cinfo->jpeg_color_space = CS_UNKNOWN;
  73.   /* Setting any other value in jpeg_color_space overrides heuristics in */
  74.   /* jrdjfif.c.  That might be useful when reading non-JFIF JPEG files, */
  75.   /* but ordinarily the UI shouldn't change it. */
  76.   
  77.   /* Default to no gamma correction of output */
  78.   cinfo->output_gamma = 1.0;
  79.   
  80.   /* Default to no color quantization */
  81.   cinfo->quantize_colors = FALSE;
  82.   /* but set reasonable default parameters for quantization, */
  83.   /* so that turning on quantize_colors is sufficient to do something useful */
  84.   cinfo->two_pass_quantize = FALSE; /* may change to TRUE later */
  85.   cinfo->use_dithering = TRUE;
  86.   cinfo->desired_number_of_colors = 256;
  87.   
  88.   /* Default to no smoothing */
  89.   cinfo->do_block_smoothing = FALSE;
  90.   cinfo->do_pixel_smoothing = FALSE;
  91.   
  92.   if (standard_buffering) {
  93.     /* Allocate memory for input buffer. */
  94.     cinfo->input_buffer = (char *) (*cinfo->emethods->alloc_small)
  95.                     ((size_t) (JPEG_BUF_SIZE + MIN_UNGET));
  96.     cinfo->bytes_in_buffer = 0;    /* initialize buffer to empty */
  97.  
  98.     /* Install standard buffer-reloading method. */
  99.     cinfo->methods->read_jpeg_data = read_jpeg_data;
  100.   }
  101. }
  102.  
  103.  
  104. /* This routine releases storage allocated by j_d_defaults.
  105.  * Note that freeing the method pointer structs and the decompress_info_struct
  106.  * itself are the responsibility of the user interface.
  107.  *
  108.  * standard_buffering must agree with what was passed to j_d_defaults.
  109.  */
  110.  
  111. GLOBAL void
  112. j_d_free_defaults (decompress_info_ptr cinfo, boolean standard_buffering)
  113. {
  114.   if (standard_buffering) {
  115.     (*cinfo->emethods->free_small) ((void *) cinfo->input_buffer);
  116.   }
  117. }
  118.